package util;

import eu.bitwalker.useragentutils.OperatingSystem;
import eu.bitwalker.useragentutils.UserAgent;
import net.sf.json.JSONObject;

/**
 * User: tum0r
 * Package Name: util
 * Time: 2019-03-10 Sunday 20:15:04
 */
public class Browser {
    public JSONObject getBrowser(String userAgent) {
        JSONObject result = JSONObject.fromObject("{}");
        if(userAgent!=null&&!userAgent.equals("")){
            UserAgent ua = UserAgent.parseUserAgentString(userAgent);
            eu.bitwalker.useragentutils.Browser browser = ua.getBrowser();
            OperatingSystem operatingSystem = ua.getOperatingSystem();
            result.put("deviceType",operatingSystem.getDeviceType().toString());
            result.put("OSManufacturer",operatingSystem.getManufacturer().toString());
            result.put("OSName",operatingSystem.getName());
            result.put("browserName",browser.getName());
        }
        return result;
    }
}
